// pages/managerDetail/managerDetail.js
import config from "../../config.js";
const openIdUrl = config;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user: null,
    keeper: null,
    manager: {
      header: "",
      name: "张伟",
      score: "9",
      level: '',
      tel: '',
      keeperType: {},
      star: []
    },
    recLIst: [],
    currentTag: 0,
    serviceLIst: []
  },

  contact: function() {
    wx.makePhoneCall({
      phoneNumber: "400-9988-960",
    })
  },
  changeTagAction: function(e) {
    var id = e.currentTarget.dataset.id;
    this.setData({
      currentTag: id
    })
    if (id != 0) {
      this.loadGJData();
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  loadGJData: function() {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: openIdUrl.ordersGJList,
      data: {
        start: 0,
        length: 5,
        type: 0,
        search: ''
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Cookie': wx.getStorageSync("session")
      },
      success: function(res) {
        console.log(res);
        wx.hideLoading();
        if (res.data.status == 200) {
          that.setData({
            serviceLIst: res.data.data
          })

        } else {
          wx.hideLoading();
          wx.showToast({
            title: res.data.message + "",
            icon: 'none',
            mask: true,
            duration: 2000
          })
        }

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    var keeper = wx.getStorageSync("MyDefaultHouseKeeper");
    var star = [];
    for (var i = 0; i < keeper.score; i++) {
      star.push(i);
    }
    if (keeper != null && keeper != '') {
      this.setData({
        manager: keeper,
        'manager.star': star
      })
    }

    this.loadData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  loadData: function() {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: openIdUrl.commentList,
      data: {
        start: 0,
        size: 10,
        search: ''
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Cookie': wx.getStorageSync("session")
      },
      success: function(res) {
        console.log(res);
        wx.hideLoading();
        if (res.data.status == 200) {
          that.setData({
            recLIst: res.data.data
          })

        } else {
          that.setData({
            recLIst: []
          })
          wx.hideLoading();
          wx.showToast({
            title: res.data.message + "",
            icon: 'none',
            mask: true,
            duration: 2000
          })
        }

      },
      error: function() {
        wx.showToast({
          title: "请求失败,请联系管理员",
          icon: 'none',
          mask: true,
          duration: 2000
        })
      }
    })

  },
  changeKeeper: function() {
    wx.navigateTo({
      url: '../managerList/managerList?isChangeDefault=1',
    })

  },
  makeCall: function(e) {
    let tel = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: tel,
    })
  },
  contactAction: function() {
    var that = this;
    //请求车辆列表
    wx.request({
      url: openIdUrl.defaultKeeperAccount,
      header: {
        'Cookie': wx.getStorageSync("session")
      },
      data: {
        start: 0
      },
      success: function(res) {
        console.log(res);
        if (res.data.status == 200) {
          wx.setStorageSync("keeperAccount", res.data.data);
          wx.navigateTo({
            url: '../msg/chat?type=2',
          })

        } else {
          wx.showToast({
            title: '即时通讯信息获取失败',
            icon: 'none'
          })
        }
      }
    })

  }
})